payload_len = int(input())
insert_data = int(input())
data_offset = []
data_len  = []
while True:
    temp = input()
    if temp == 'end':break
    temp = temp.split(',')
    temp = list(map(int, temp))
    data_offset.append(temp[0])
    data_len.append(temp[1])
if insert_data < data_offset[0]:
    data_offset[0] =  data_offset[0] - insert_data
    new_offset = data_offset
    new_data = data_len
else:
    num = int(insert_data/payload_len)+1
    new_data = []
    new_offset = []
    for i in range(int(insert_data/payload_len)):
        new_data.append(payload_len)
        new_offset.append(0)
    new_data.append(insert_data%payload_len)
    new_offset.append(0)
    new_data.extend(data_len)
    new_offset.extend(data_offset)
for i in range(len(new_data)):
    print('{0},{1}'.format(new_offset[i], new_data[i]))

